import 'package:flutter/material.dart';
import 'package:super_tool_server/component/animation/rotate_animation_widget.dart';
import 'package:super_tool_server/component/iconfont.dart';
import 'package:super_tool_server/component/image/image_view.dart';
import 'package:super_tool_server/component/theme/theme.dart';
import 'package:super_tool_server/resource/r.dart';

enum LoadingAnimationStyle {
  circle,
  circleBlack,
  circleAllWhite,
  circleAllPrimary,
}

class LoadingAnimationWidget extends StatelessWidget {
  LoadingAnimationWidget({
    this.style = LoadingAnimationStyle.circle,
    this.size = 80,
    this.isPlaying = true,
  });

  final LoadingAnimationStyle style;
  final double size;
  final bool isPlaying;

  @override
  Widget build(BuildContext context) {
    if (style == LoadingAnimationStyle.circle) {
      return RotateAnimationWidget(
        isPlaying: isPlaying,
        child: ImageViewWidget.asset(
          imageUrl: R.svgLoadingIconWhiteSvg,
          width: size,
          height: size,
          // package: 'ui_component',
        ),
      );
    } else if (style == LoadingAnimationStyle.circleBlack) {
      return RotateAnimationWidget(
        isPlaying: isPlaying,
        speed: 400,
        child: Center(
          child: ImageViewWidget.asset(
            imageUrl: R.svgLoadingIconWhiteSvg,
            width: size,
            height: size,
            color: CustomTheme.of(context)!.colors.text.gray60,
            // package: 'ui_component',
          ),
        ),
      );
    } else if (style == LoadingAnimationStyle.circleAllWhite) {
      return RotateAnimationWidget(
        child: Icon(
          AppIconData.loading,
          size: size,
          color: Colors.white,
        ),
      );
    } else if (style == LoadingAnimationStyle.circleAllPrimary) {
      return RotateAnimationWidget(
        child: Icon(
          AppIconData.loading,
          size: size,
          color: CustomTheme.of(context)!.colors.primary,
        ),
      );
    }

    return Container();
  }
}
